#ifndef PMDFILE_H
#define PMDFILE_H

#include <QObject>
#include <qfile.h>
#include <qdatastream.h>
#include <qdir.h>
#include <qstringlist.h>
#include <qdebug.h>
#include <qtextcodec.h>

#include "MMD\PMDTypes.h"

#include <iostream>
#include <Eigen/Geometry>

using namespace Eigen;

//struct PmdHeader {
//	char pmd[3];
//	float version;
//	char name[20];
//	char comment[256];
//};
//
//struct PmdVertex
//{
//	float x, y, z, xn, yn, zn, u, v;
//
//	unsigned short boneNo[2];
//	unsigned char weight;
//	unsigned char edge;
//};

class PmdVertex {
public:
	PmdVertex() {}
	~PmdVertex() {}

	Vector3f pos;
	Vector3f normal;
	Vector2f tex;
	unsigned short boneNo[2];
	float weight;
	float edge;
};

class PmdBone {
public:
	PmdBone();
	~PmdBone();

	char szName[21];
	int parentNo;
	int childNo;

	int kind;
	int ikTarget;

	Vector3f pos;

	PmdBone* parent;   // assigned based on value of parentNo
	PmdBone* child;		// assigned based on value of childNo
	Vector3f localPos; // calculated value
	QString engName;

	Vector3f posOffset;
	Vector4f rotOffset;

	Vector3f calcGlobalPos();
	Vector3f calcGlobalPos(Vector3f lPos);
	static Matrix3f quat2matrix(double e1, double e2, double e3, double e4);
};

class PmdFile : public QObject
{
	Q_OBJECT

public:
	PmdFile();
	~PmdFile();

	void readFile(QString filePath);
	
	QVector<PmdVertex> vertexList;
	QVector<PmdBone> boneList;

private:
	QString m_path;
	unsigned char* m_data;
	long long m_fileSize;

	//PmdHeader m_header;
	//unsigned long m_vertexCount;
	//QList<PmdVertex> vertexList	
};

#endif // PMDFILE_H
